﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using System.IO;
using WeChatApp.Repositories;

namespace WeChatApp.Controllers
{
    [Route("kallen/[controller]")]
    [ApiController]
    public class FileController : BaseController
    {
        // GET api/values
        [HttpGet]
        public ActionResult<IEnumerable<string>> Get()
        {
            var fl = RepositoryFactoryInst.GetRepository<FileRepository>();
            var res = fl.MakeFiletxt("新建文本文档.txt");
            var actionresule = new FileStreamResult(res, "text/plain");
            actionresule.FileDownloadName = "xinxinxin.txt";
            return actionresule;
        }
        // GET api/values
        [HttpGet("{filename}")]
        public ActionResult<IEnumerable<string>> Get(string filename)
        {
            var fl = RepositoryFactoryInst.GetRepository<FileRepository>();
            var res = fl.MakeFiletxt(filename);
            var actionresule = new FileStreamResult(res, "image/jpeg");
            actionresule.FileDownloadName = filename;
            return actionresule;
        }
    }
}